package com.hunk.core.tiles.controller;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.hunk.utils.io.Print;

@Controller
@RequestMapping("/tiles")
public class TilesController {

	@Autowired
	JdbcTemplate jdbcTemplate;
	
	@RequestMapping("/home")
	public ModelAndView toHome(@RequestParam(value="day",required=false) String day) {
		if (!StringUtils.isNotEmpty(day)) day = "2013-03-23"; 
		List list = jdbcTemplate.queryForList("select * from view_component where update_date = '" + day + "' order by orders");
		Print.println(list.size());
		
		ModelAndView mav = new ModelAndView();
		mav.setViewName("content/home");
		ModelMap map = mav.getModelMap();
		map.addAttribute("view_cop", list);		
		return mav;
	}
}
